<?php
/**
 * Created by PhpStorm.
 * User: wanghaibo
 * Date: 17/4/27
 * Time: 13:47
 */

namespace Portal\Controller;


use Common\Controller\AdminbaseController;

class AdminSiteController extends AdminbaseController
{
    protected $posts_model;

    function _initialize() {
        parent::_initialize();
        $this->main_model = D('Common/Site');
        $this->posts_model =D("Common/Posts");
    }

    // 后台页面管理列表
    public function index(){
        $this->_lists();
        $this->display();
    }

    /**
     * 页面列表处理方法,根据不同条件显示不同的列表
     * @param array $where 查询条件
     */
    private function _lists($where=array()){



        $count=$this->main_model->count();

        $page = $this->page($count, 20);

        $posts=$this->main_model
            ->limit($page->firstRow , $page->listRows)
            ->order("listorder asc,id DESC")
            ->select();
        $this->assign("page", $page->show('Admin'));
        $this->assign("posts",$posts);
    }

    // 页面添加
    public function add(){
        if(IS_POST){
            if($this->main_model->create()){
                if($this->main_model->add())
                    $this->success('添加成功');
                else
                    $this->error($this->main_model->getError());
            }else{
                $this->error($this->main_model->getError());
            }
        }
        $location = getCoor('219.155.6.245');
        $point = $location['content']['point'];
        $this->assign('ip','219.155.6.245');
        $this->assign('point',$point);
        $this->display();
    }


    // 页面编辑
    public function edit(){
        if(IS_POST){
            if($this->main_model->create()){
                if($this->main_model->save())
                    $this->success('编辑成功');
                else
                    $this->error($this->main_model->getError());
            }else{
                $this->error($this->main_model->getError());
            }
        }
        $id = I('get.id');
        $info = $this->main_model->where(array('id'=>$id))->find();
        $xyz = explode(',',$info['xyz']);
        $point['x'] = $xyz[0];
        $point['y'] = $xyz[1];
        $this->assign('info',$info);
        $this->assign('point',$point);
        $this->display();
    }

    // 删除场馆
    public function delete() {
        $id = I("get.id",0,'intval');

        if ($this->main_model->delete($id)!==false) {
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
    }
    // 文章分类排序
    public function listorders() {
        $status = parent::_listorders($this->main_model);
        if ($status) {
            $this->success("排序更新成功！");
        } else {
            $this->error("排序更新失败！");
        }
    }

}